package com.speed_run.controller;

import lombok.extern.log4j.Log4j2;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.speed_run.global.BusinessException;


/**
 * 全局异常处理类
 * @author wafer
 * 
 */
@ControllerAdvice
@ResponseBody
@Log4j2
public class ExceptionController {

	
	
	@ExceptionHandler
	public Object runTimeException(Exception e){
		/**
		 * TODO 异常日志保存
		 */
		e.printStackTrace();
		//log.error(e.getMessage());
		return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
	}
	
	
	@ExceptionHandler(BusinessException.class)
	public Object businessException(Exception e){
		/**
		 * TODO 异常日志保存
		 */
		e.printStackTrace();
		//log.error(e.getMessage());
		return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
	}
	
	/**
	 * 
	 * 
	 * @ExceptionHandler(XXXXException.class)
	 * 
	 * 
	 * 
	 */
	
	
}
